<?php
namespace app\system\validate;
use think\Validate;

class SuperAdmin extends Validate
{
    // 验证规则
    protected $rule = [
        ['add_domain', 'require|checkDomain:1', '-11402|-22001'],
        ['no_token', 'require', '-11407'],
        ['id', 'require', '-22002'],
    ];

    protected $scene = [
        'updata' => ['no_token','add_domain'],
        'del' => ['no_token','id'],
    ];
    //页面id是否唯一
    protected function checkDomain($value,$rule,$data){
        try {
            $where['web_id'] = $data['web_id'];
            if(!empty($data['id'])) $where['id'] = ['neq',$data['id']];
            return \app\common\model\Base::get_table_info($where,'id','SuperAdmin') ? "-22001" : true ;
        }catch(\Exception $e){
            return false;
        }
    }
}